﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using QLNHK.BLL;
using System.Threading;
using Infragistics.Win.UltraWinGrid;

namespace QLNHK
{
    public partial class FrmQuanLyDoiTuong : frmBase_Rebind
    {
        private DataSet dsData = new DataSet();
        private string whereCondition, whereConditionNangCao, orderBy;
        private int tongSoNhanKhau, tongNam, tongNu;
        frmWait frmWaiting;

        #region Set Authentication On Form
        private cls_Role ObjRole = null;
        private Cls_PHANQUYEN_NHOM ObjPhanQuyen = null;
        private Infragistics.Win.DefaultableBoolean GetStatus(bool values)
        {
            if (values)
            {
                return Infragistics.Win.DefaultableBoolean.True;
            }
            else
            {
                return Infragistics.Win.DefaultableBoolean.False;
            }
        }
        private void SetAuthenticationOnForm()
        {
            try
            {
                if (!frmMain.ObjNguoiDung.IsAdministrator)
                {
                    ObjRole = new cls_Role();
                    ObjPhanQuyen = new Cls_PHANQUYEN_NHOM();

                    ObjRole = new cls_Role(Global.GetRole(ObjPhanQuyen.GetRoleByIDChucNang(frmMain.ObjNguoiDung.ID_NguoiDung, this.Tag.ToString())));

                    if (ObjRole != null)
                    {
                        if (ObjRole.HienThi == false)//không hiển thị
                        {
                            foreach (Control ctl in this.Controls)
                            {
                                ctl.Visible = false;
                            }
                        }
                        //chỉ cho phép hiển thị, không cho phép cập nhật, sửa, xóa
                        else if (ObjRole.HienThi == true && ObjRole.Them == false && ObjRole.Sua == false && ObjRole.Xoa == false)
                        {
                            //Grid tom tat ban than
                            gridDoiTuong.DisplayLayout.Bands[0].Override.AllowDelete = GetStatus(ObjRole.Xoa);
                            gridDoiTuong.DisplayLayout.Bands[0].Override.AllowUpdate = GetStatus(ObjRole.Sua);
                            if (ObjRole.Them)
                                gridDoiTuong.DisplayLayout.Bands[0].Override.AllowAddNew = AllowAddNew.TemplateOnTopWithTabRepeat;

                            btnAdd.Enabled = ObjRole.Them;
                            btnEdit.Enabled = ObjRole.Sua;
                            btnDel.Enabled = ObjRole.Xoa;
                        }
                        //cho phép hiển thị, cho phép hoặc cập nhật, hoặc sửa, hoặc xóa
                        else
                        {
                            CheckAuthentication();
                        }
                    }
                }

                btnClose.Enabled = true;
            }

            catch (Exception ex)
            {
                Logger.LocalLogger.Instance().WriteMessage(ex);
            }
        }
        private void CheckAuthentication()
        {
            try
            {
                if (ObjRole != null)
                {
                    //Grid tom tat ban than
                    gridDoiTuong.DisplayLayout.Bands[0].Override.AllowDelete = GetStatus(ObjRole.Xoa);
                    btnDel.Enabled = ObjRole.Xoa;

                    gridDoiTuong.DisplayLayout.Bands[0].Override.AllowUpdate = GetStatus(ObjRole.Sua);
                    btnEdit.Enabled = ObjRole.Sua;

                    if (ObjRole.Them)
                        gridDoiTuong.DisplayLayout.Bands[0].Override.AllowAddNew = AllowAddNew.TemplateOnTopWithTabRepeat;
                    else
                        gridDoiTuong.DisplayLayout.Bands[0].Override.AllowAddNew = AllowAddNew.No;
                    btnAdd.Enabled = ObjRole.Them;
                }
            }
            catch (Exception ex)
            {
                Logger.LocalLogger.Instance().WriteMessage(ex);
            }
        }
        #endregion

        public FrmQuanLyDoiTuong()
        {
            InitializeComponent();
        }
        private void FrmQuanLyDoiTuong_Load(object sender, EventArgs e)
        {
            try
            {
                btnClear.PerformClick();

                frmWaiting = new frmWait();
                ThreadPool.QueueUserWorkItem(OnProcess);
                frmWaiting.ShowDialog(this);
            }
            catch (Exception ex) { Logger.LocalLogger.Instance().WriteMessage(ex); }
        }
        private void OnProcess(object o)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new MethodInvoker(delegate
                {
                    frmWaiting.SetCaption("Vui lòng chờ giây lát");

                    //Load data tại đây
                    this.LoadData(ref frmWaiting);
                    frmWaiting.DialogResult = DialogResult.OK;
                }));
            }
        }

        private void cboThanhPho_ValueChanged(object sender, EventArgs e)
        {
            if (cboThanhPho.Value != null)
            {
                int cboThanhPhoValue = 0;
                Int32.TryParse(cboThanhPho.Value.ToString(), out cboThanhPhoValue);
                if (cboThanhPhoValue > 0)
                    Global.setDataToComboQuanHuyen(cboQuanHuyen, Convert.ToInt32(cboThanhPho.Value));
            }
        }
        private void cboQuanHuyen_ValueChanged(object sender, EventArgs e)
        {
            if (cboQuanHuyen.Value != null)
            {
                int cboQuanHuyenValue = 0;
                Int32.TryParse(cboQuanHuyen.Value.ToString(), out cboQuanHuyenValue);
                if (cboQuanHuyenValue > 0)
                    Global.setDataToComboXaPhuong(cboXaPhuong, Convert.ToInt32(cboQuanHuyen.Value));
            }
        }
        private void cboXaPhuong_ValueChanged(object sender, EventArgs e)
        {
            if (cboXaPhuong.Value != null)
            {
                int cboXaPhuongValue = 0;
                Int32.TryParse(cboXaPhuong.Value.ToString(), out cboXaPhuongValue);
                if (cboXaPhuongValue > 0)
                    Global.setDataToComboToDanPho(cboToDanPho, Convert.ToInt32(cboXaPhuong.Value));
            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            try
            {
                Global.setDataToComboDanhMuc(cboLoaiDoiTuong, DMCatalogue.DM_LOAIDOITUONG);
                txtMaDoiTuong.Text = txtHoTen.Text = txtSoCMND.Text = txtDiaChi.Text = string.Empty;
                Global.setDataToComboNamSinh(cboNamSinhTu); Global.setDataToComboNamSinh(cboNamSinhDen);
                optGioiTinh.CheckedIndex = 0;
                //Set dia ban
                Global.setDataToComboThanhPho(cboThanhPho); cboThanhPho.Value = ConfigNHK.Install.ThanhPho; // Global.DIABAN_THANHPHO;
                Global.setDataToComboQuanHuyen(cboQuanHuyen, (int)cboThanhPho.Value);
                Global.setDataToComboXaPhuong(cboXaPhuong, (int)cboQuanHuyen.Value);
                Global.setDataToComboToDanPho(cboToDanPho, (int)cboXaPhuong.Value);

                //Nang cao
                chkGayAnBoNoiCuTru.Checked = chkGayAnLuuDong.Checked = chkGayAnTaiDiaPhuong.Checked = true;
                chkPVHDLienTinh.Checked = chkPVHDLienQuan.Checked = chkPVHDLienXa.Checked = chkPVHDTaiNoiCuTru.Checked = true;
                txtCao.Text = txtDaiTai.Text = txtDauVet.Text = txtGiongNoi.Text = txtMauDa.Text = txtNepTai.Text = txtSongMui.Text = txtTamVoc.Text = string.Empty;

                txtHoTen.Focus();
            }
            catch (Exception ex) { Logger.LocalLogger.Instance().WriteMessage(ex); }
        }
        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            frmWaiting = new frmWait();
            ThreadPool.QueueUserWorkItem(OnProcess);
            frmWaiting.ShowDialog(this);
        }
        private void LoadData(ref frmWait frmW)
        {
            try
            {
                //Load data
                whereCondition = "1=1 AND MaDoiTuong <> ''";

                //Loai doi tuong
                if (System.Convert.ToInt32(cboLoaiDoiTuong.Value) > 0)
                    whereCondition += string.Format(" AND (LoaiDoiTuongID = {0})", cboLoaiDoiTuong.Value);
                //Ma doi tuong
                if (txtMaDoiTuong.Text.Trim().Length > 0)
                {
                    if (chkTimChinhXac.Checked)
                        whereCondition += " AND MaDoiTuong = '" + txtMaDoiTuong.Text.Trim() + "'";
                    else
                        whereCondition += " AND MaDoiTuong like '%" + txtMaDoiTuong.Text.Trim() + "%'";
                }
                //Ho ten
                if (txtHoTen.Text.Trim().Length > 0)
                {
                    if (chkTimChinhXac.Checked)
                        whereCondition += " AND (HoLot = N'" + txtHoTen.Text.Trim() + "' OR Ten = N'" + txtHoTen.Text.Trim() + "')";
                    else
                        whereCondition += " AND (HoLot like N'%" + txtHoTen.Text.Trim() + "%' OR Ten like N'%" + txtHoTen.Text.Trim() + "%')";
                }
                //So CMND
                if (txtSoCMND.Text.Trim().Length > 0)
                {
                    if (chkTimChinhXac.Checked)
                        whereCondition += " AND SoCMND = '" + txtSoCMND.Text.Trim() + "'";
                    else
                        whereCondition += " AND SoCMND like '%" + txtSoCMND.Text.Trim() + "%'";
                }
                //Nam sinh
                if (System.Convert.ToInt32(cboNamSinhTu.Value) > 0 && System.Convert.ToInt32(cboNamSinhDen.Value) > 0)
                {
                    whereCondition += " AND (NamSinh between " + System.Convert.ToInt32(cboNamSinhTu.Value) + " AND " + System.Convert.ToInt32(cboNamSinhDen.Value) + ")";
                }
                //Gioi tinh
                if (System.Convert.ToInt32(optGioiTinh.Value) != -1)
                    whereCondition += " AND (GioiTinh = " + System.Convert.ToInt32(optGioiTinh.Value) + ")";
                //Dia chi
                if (txtDiaChi.Text.Length > 0)
                {
                    if (chkTimChinhXac.Checked)
                        whereCondition += string.Format(" AND (ThuongTruDiaChi = N'{0}' OR NoiOHienNayDiaChi = N'{0}')", txtDiaChi.Text);
                    else
                        whereCondition += string.Format(" AND (ThuongTruDiaChi like N'%{0}%' OR NoiOHienNayDiaChi like N'%{0}%')", txtDiaChi.Text);
                }
                if (System.Convert.ToInt32(cboThanhPho.Value) > 0)
                    whereCondition += string.Format(" AND (QueQuanTinhTPID = {0} OR ThuongTruTinhTPID = {0} OR NoiOHienNayTinhTPID = {0})", cboThanhPho.Value);
                if (System.Convert.ToInt32(cboQuanHuyen.Value) > 0)
                    whereCondition += string.Format(" AND (QueQuanQuanHuyenID = {0} OR ThuongTruQuanHuyenID = {0} OR NoiOHienNayQuanHuyenID = {0})", cboQuanHuyen.Value);
                if (System.Convert.ToInt32(cboXaPhuong.Value) > 0)
                    whereCondition += string.Format(" AND (QueQuanXaPhuongID = {0} OR ThuongTruXaPhuongID = {0} OR NoiOHienNayXaPhuongID = {0})", cboXaPhuong.Value);
                if (System.Convert.ToInt32(cboToDanPho.Value) > 0)
                    whereCondition += string.Format(" AND (QueQuanToID = {0} OR ThuongTruToID = {0} OR NoiOHienNayToID = {0})", cboToDanPho.Value);
                //Dac diem doi tuong
                if (txtCao.Text.Length > 0)
                {
                    if (chkTimChinhXac.Checked)
                        whereCondition += " AND (Cao like N'%" + txtCao.Text + "%')";
                    else
                        whereCondition += " OR (Cao like N'%" + txtCao.Text + "%')";
                }
                if (txtDaiTai.Text.Length > 0)
                {
                    if (chkTimChinhXac.Checked)
                        whereCondition += " AND (DaiTai like N'%" + txtDaiTai.Text + "%')";
                    else
                        whereCondition += " OR (DaiTai like N'%" + txtDaiTai.Text + "%')";
                }
                if (txtDauVet.Text.Length > 0)
                {
                    if (chkTimChinhXac.Checked)
                        whereCondition += " AND (DauVet like N'%" + txtDauVet.Text + "%')";
                    else
                        whereCondition += " OR (DauVet like N'%" + txtDauVet.Text + "%')";
                }
                if (txtGiongNoi.Text.Length > 0)
                {
                    if (chkTimChinhXac.Checked)
                        whereCondition += " AND (GiongNoi like N'%" + txtGiongNoi.Text + "%')";
                    else
                        whereCondition += " OR (GiongNoi like N'%" + txtGiongNoi.Text + "%')";
                }
                if (txtMauDa.Text.Length > 0)
                {
                    if (chkTimChinhXac.Checked)
                        whereCondition += " AND (MauDa like N'%" + txtMauDa.Text + "%')";
                    else
                        whereCondition += " OR (MauDa like N'%" + txtMauDa.Text + "%')";
                }
                if (txtNepTai.Text.Length > 0)
                {
                    if (chkTimChinhXac.Checked)
                        whereCondition += " AND (NepTai like N'%" + txtNepTai.Text + "%')";
                    else
                        whereCondition += " OR (NepTai like N'%" + txtNepTai.Text + "%')";
                }
                if (txtSongMui.Text.Length > 0)
                {
                    if (chkTimChinhXac.Checked)
                        whereCondition += " AND (SongMui like N'%" + txtSongMui.Text + "%')";
                    else
                        whereCondition += " OR (SongMui like N'%" + txtSongMui.Text + "%')";
                }
                if (txtTamVoc.Text.Length > 0)
                {
                    if (chkTimChinhXac.Checked)
                        whereCondition += " AND (TamVoc like N'%" + txtTamVoc.Text + "%')";
                    else
                        whereCondition += " OR (TamVoc like N'%" + txtTamVoc.Text + "%')";
                }

                //Nang cao
                whereConditionNangCao = "1=1";
                //Dia ban gay an
                if (chkGayAnTaiDiaPhuong.Checked)
                    whereConditionNangCao += " AND (DiaBanGayAns like '%" + (int)EDiaBanGayAn.TaiDiaPhuong + "%')";
                if (chkGayAnLuuDong.Checked)
                {
                    if (chkTimChinhXac.Checked)
                        whereConditionNangCao += " AND (DiaBanGayAns like '%" + (int)EDiaBanGayAn.LuuDongTrenTuyen + "%')";
                    else
                        whereConditionNangCao += " OR (DiaBanGayAns like '%" + (int)EDiaBanGayAn.LuuDongTrenTuyen + "%')";
                }
                if (chkGayAnBoNoiCuTru.Checked)
                {
                    if (chkTimChinhXac.Checked)
                        whereConditionNangCao += " AND (DiaBanGayAns like '%" + (int)EDiaBanGayAn.BoNoiCuTruDenCacThanhPhoHoatDong + "%')";
                    else
                        whereConditionNangCao += " OR (DiaBanGayAns like '%" + (int)EDiaBanGayAn.BoNoiCuTruDenCacThanhPhoHoatDong + "%')";
                }
                //Pham vi hoat dong
                if (chkPVHDLienTinh.Checked)
                {
                    if (chkTimChinhXac.Checked)
                        whereConditionNangCao += " AND (PhamViHoatDongs like '%" + (int)EPhamViHoatDong.LienTinh + "%')";
                    else
                        whereConditionNangCao += " OR (PhamViHoatDongs like '%" + (int)EPhamViHoatDong.LienTinh + "%')";
                }
                if (chkPVHDLienQuan.Checked)
                {
                    if (chkTimChinhXac.Checked)
                        whereConditionNangCao += " AND (PhamViHoatDongs like '%" + (int)EPhamViHoatDong.LienQuan + "%')";
                    else
                        whereConditionNangCao += " OR (PhamViHoatDongs like '%" + (int)EPhamViHoatDong.LienQuan + "%')";
                }
                if (chkPVHDLienXa.Checked)
                {
                    if (chkTimChinhXac.Checked)
                        whereConditionNangCao += " AND (PhamViHoatDongs like '%" + (int)EPhamViHoatDong.LienXa + "%')";
                    else
                        whereConditionNangCao += " OR (PhamViHoatDongs like '%" + (int)EPhamViHoatDong.LienXa + "%')";
                }
                if (chkPVHDTaiNoiCuTru.Checked)
                {
                    if (chkTimChinhXac.Checked)
                        whereConditionNangCao += " AND (PhamViHoatDongs like '%" + (int)EPhamViHoatDong.TaiNoiCutru + "%')";
                    else
                        whereConditionNangCao += " OR (PhamViHoatDongs like '%" + (int)EPhamViHoatDong.TaiNoiCutru + "%')";
                }
                //Thuc hien tim kiem thong tin trong bang Tien an cua nhan khau truoc
                dsData = DoiTuong_TienAn.SelectDynamic(whereConditionNangCao, "");
                string strIDNhanKhau = string.Empty;
                if (dsData.Tables.Count > 0 && dsData.Tables[0].Rows.Count > 0)
                {
                    for (int k = 0; k < dsData.Tables[0].Rows.Count; k++)
                    {
                        strIDNhanKhau += dsData.Tables[0].Rows[k]["DoiTuongID"].ToString();

                        if (k < dsData.Tables[0].Rows.Count - 1)
                            strIDNhanKhau += ",";
                    }
                }

                //Neu tim thay thong tin Tien an cua doi tuong, bo sung thong tin duoc tim thay do vao thong tin tiem kiem chung
                if (strIDNhanKhau.Length > 0)
                {
                    if (chkTimChinhXac.Checked)
                        whereCondition += " AND ID IN(" + strIDNhanKhau + ")";
                    else
                        whereCondition += " OR ID IN(" + strIDNhanKhau + ")";
                }

                orderBy = "MaDoiTuong asc";
                dsData = DoiTuong.SearchBy(whereCondition, orderBy);
                gridDoiTuong.DataSource = dsData.Tables[0];

                tongSoNhanKhau = dsData.Tables[0].Rows.Count;
                tongNam = dsData.Tables[0].Select("GioiTinh = 1").Length;
                tongNu = dsData.Tables[0].Select("GioiTinh = 0").Length;
                lblTongSo.Text = string.Format("Tổng số đối tượng: {0} - Nam: {1}, Nữ: {2}", tongSoNhanKhau, tongNam, tongNu);

                //Kiem tra phan quyen sau khi nap du lieu
                SetAuthenticationOnForm();
            }
            catch (Exception ex)
            {
                Logger.LocalLogger.Instance().WriteMessage(ex);
                MessageBox.Show(ex.Message);
            }
        }

        private void gridDoiTuong_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            try
            {
                e.Layout.Override.CellClickAction = CellClickAction.RowSelect;

                UltraGridBand band = e.Layout.Bands[0];
                band.Columns["ID"].Hidden = true;
                band.Columns["DoiTuongPhanLoaiID"].ValueList = Global.getValueListDanhMuc(DMCatalogue.DM_LOAIDOITUONG);
                band.Columns["DoiTuongPhanLoaiID"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
                band.Columns["DoiTuongPhanLoaiID"].CellActivation = Activation.NoEdit;
                band.Columns["GioiTinh"].ValueList = Global.getValueListGioiTinh();
                band.Columns["GioiTinh"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
                band.Columns["GioiTinh"].CellActivation = Activation.NoEdit;
            }
            catch (Exception ex) { Logger.LocalLogger.Instance().WriteMessage(ex); }
        }
        private void gridDoiTuong_DoubleClickRow(object sender, DoubleClickRowEventArgs e)
        {
            EditDoiTuong();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //Open form to edit
            FrmThemMoiDoiTuong frm = new FrmThemMoiDoiTuong();
            frm.ShowDialog();

            //Update row add on grid
            btnTimKiem.PerformClick();
        }
        private void btnEdit_Click(object sender, EventArgs e)
        {
            EditDoiTuong();
        }
        private void btnDel_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor = Cursors.WaitCursor;

                if (gridDoiTuong.ActiveRow != null && gridDoiTuong.ActiveRow.Cells["ID"].Value != null)
                {
                    //Get ID nhan khau
                    int nkID = System.Convert.ToInt32(gridDoiTuong.ActiveRow.Cells["ID"].Value);
                    DoiTuong delDT = DoiTuong.Load(nkID);
                    string hoTen = delDT.HoLot + " " + delDT.Ten;

                    //Truong hop khong co nha khau nao:
                    if (DialogResult.OK == MessageBox.Show("Bạn có chắc chắn muốn xóa thông tin đối tượng '" + hoTen + "' này không?.", this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                    {
                        //Xoa thong tin nhan khau chi tiet truoc khi xoa thong tin nha khau
                        DoiTuong_HinhAnh.DeleteBy_DoiTuongID(nkID);
                        DoiTuong_TienAn.DeleteBy_DoiTuongID(nkID);

                        DoiTuong.DeleteDoiTuong(nkID);

                        MessageBox.Show("Đã xóa thành công thông tin đối tượng '" + hoTen + "'.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);

                        btnTimKiem.PerformClick();
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LocalLogger.Instance().WriteMessage(ex);
                MessageBox.Show("Lỗi trong quá trình xóa thông tin hộ khẩu: " + ex.Message);
            }
            finally { Cursor = Cursors.Default; }
        }
        private void EditDoiTuong()
        {
            try
            {
                Cursor = Cursors.WaitCursor;

                if (gridDoiTuong.ActiveRow != null && gridDoiTuong.ActiveRow.Cells["ID"].Value != null)
                {
                    //Get ID nhan khau
                    int nkID = System.Convert.ToInt32(gridDoiTuong.ActiveRow.Cells["ID"].Value);
                    DoiTuong editDT = DoiTuong.Load(nkID);

                    //Open form to edit
                    FrmThemMoiDoiTuong frm = new FrmThemMoiDoiTuong();
                    frm.ObjDoiTuong = editDT;
                    frm.ShowDialog();

                    //Update row edit on grid
                    btnTimKiem.PerformClick();
                }
            }
            catch (Exception ex)
            {
                Logger.LocalLogger.Instance().WriteMessage(ex);
                MessageBox.Show(ex.Message);
            }
            finally { Cursor = Cursors.Default; }
        }
        private void btnXuatExcel_Click(object sender, EventArgs e)
        {
            XuatExcel("Danh sach doi tuong", saveFileDialog1, excelExporter, Infragistics.Excel.WorkbookFormat.Excel97To2003, gridDoiTuong);
        }
        private void XuatExcel(
            string fileName,
            SaveFileDialog saveDialog,
            Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter exporter,
            Infragistics.Excel.WorkbookFormat excelType,
            Infragistics.Win.UltraWinGrid.UltraGrid grid)
        {
            try
            {
                Cursor = Cursors.WaitCursor;

                saveDialog.FileName = fileName;
                saveDialog.Filter = "Excel files (*.xls, *.xlxs)|*.xls;*.xlxs";
                if (DialogResult.OK == saveDialog.ShowDialog())
                {
                    if (saveDialog.FileName.Length > 0)
                    {
                        excelExporter.Export(grid, saveDialog.FileName, excelType);

                        if (DialogResult.OK == MessageBox.Show("Bạn có muốn mở tệp tin Excel được xuất ra không?", this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                        {
                            System.Diagnostics.Process.Start(saveDialog.FileName);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LocalLogger.Instance().WriteMessage(ex);
                MessageBox.Show(ex.Message);
            }
            finally { Cursor = Cursors.Default; }
        }
        private void FrmQuanLyDoiTuong_DiaBanChanged()
        {
            try
            {
                Cursor = Cursors.WaitCursor;

                cboThanhPho.Value = Global.CACHE_THANHPHO_ID;
                cboQuanHuyen.Value = Global.CACHE_QUANHUYEN_ID;
                cboXaPhuong.Value = Global.CACHE_XAPHUONG_ID;

                btnTimKiem.PerformClick();
            }
            catch (Exception ex)
            {
                Logger.LocalLogger.Instance().WriteMessage(ex);
                MessageBox.Show(ex.Message);
            }
            finally { Cursor = Cursors.Default; }
        }
    }
}